home *** CD-ROM | disk | FTP | other *** search
/ Beginning Mac Programming / Beginning Mac Programming.bin / pc / Open Me for REALbasic 3 / REALbasic 3.2 / Goodies / 3rd Party Demos / 3rd Party Plugins / Misc / PEVocoder 1.0 (PPC) / PEVocodePlugin Source Code / fftaux.cp < prev    next >
Encoding:
Text File  |  1998-09-12  |  1.5 KB  |  61 lines

  1. /* $Id: fftaux.c,v 1.2 1998/09/13 00:21:18 emanuel Exp $ */
  2.  
  3. #include "fft.h"
  4.  
  5. /* Here are the integer based support routines for the fftlib */
  6.  
  7. /* This routine reverses the bits in integer */
  8. unsigned bitrev(unsigned int k, int nu)
  9. /* register unsigned k; * Number to reverse the bits of */
  10. /* int nu;              * Number of bits k is represented by */
  11. {
  12.     register int i;
  13.     register unsigned out = 0;
  14.     
  15.     for (i = 0; i < nu; i++) {
  16.         out <<= 1;
  17.         out |= k & 1;
  18.         k >>= 1;
  19.     }
  20.     return(out);
  21. }
  22.  
  23.  
  24. /* Computes a^b where a and b are integers */
  25. int ipow(int a, int b)
  26. {
  27.     register int i;
  28.     int sum = 1;
  29.     
  30.     for (i = 0; i < b; i++)     
  31.         sum *= a;
  32.     return (sum);
  33. }
  34.  
  35. /* Computes log2(n).  Returns -1 if n == 0*/
  36. int ilog2(int n)
  37. {
  38.     register int i;
  39.     
  40.     for (i = -1; n != 0; i++, n>>=1)
  41.         ;
  42.     return(i);
  43. }
  44.  
  45. /* getindex - gets one real, imag pair from the square multidimensional array */
  46. int getindex(int ndim, int dim, int n, int elem[])
  47. /* int ndim;                      * Number of dimensions */
  48. /* int dim;                        * Dim to extract point from */
  49. /* int n;                           * Number of points in each dim */
  50. /* int elem[];                    * Which element to extract (array by ndim) */
  51. {
  52.     register int i;
  53.     int pos=0;                  /* Position in array when considered 1d */
  54.  
  55.     for (i = 0; i < ndim && (pos *= n); i++)  /* Loop over dimensions */
  56.         pos += elem[i];
  57.  
  58.     return(pos);
  59. }
  60.  
  61.